﻿$(document).ready(function() {
	
	$("button.validate").click(function() {
		if (!validate('lettral_user_register')) {
			return false;
		}
		
		$.fancybox.showActivity();   
		$.ajax({ 
                type: "POST", 
                data: $('#lettral_user_register').serialize(), 
                url: $('form#lettral_user_register').attr('action'),
                success: function(data) {
                	$.fancybox.hideActivity();
                	var response = eval(data);
                	if (response.status == "success") {
                		window.location.href = "../..";
                	}
                	else {
                		console.log(response);
                		$(response).each(function () {
                			displayErrorMessage('lettral_user_register', this.id, this.message);
                    });
                	}
                } 
        });
	});
});